package com.duowan.mspider.util;

import com.google.common.collect.Lists;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.List;

/**
 * @author:wangyan1
 * @create_time: 2018-04-11 17:38
 */

public class FileUtils {

	public static List<String> read(File file) {
		try (

					BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8))
		) {
			List<String> keywords = Lists.newArrayList();
			String line = null;
			while ((line = reader.readLine()) != null) {
				keywords.add(line.trim());
			}

			return keywords;
		} catch (Exception e) {
			e.printStackTrace();
			return Lists.newArrayList();
		}
	}

	public static void write(File file, String content) throws IOException {
		try (
					BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, true), StandardCharsets.UTF_8))//追加模式
		) {
			writer.append(content).append("\r\n").flush();
		}
	}
}
